package com.fang.transfer.file.client.listener;

import com.fang.transfer.file.client.AppContext;
import com.fang.transfer.file.common.RequestListener;
import com.fang.transfer.file.common.code.ClientSendCode;
import com.fang.transfer.file.common.code.ServiceSendCode;
import com.fang.transfer.file.common.model.TransferFileRequest;
import com.fang.transfer.file.common.model.User;

import java.io.IOException;
import java.io.RandomAccessFile;

/**
 * 关闭资源
 */
public class CloseResourcesListener extends RequestListener<TransferFileRequest> {


    @Override
    public void handle(TransferFileRequest param) throws IOException {
        AppContext.udpServiceMap.remove(param.getId());
        AppContext.transferFileRequestMap.remove(param.getId());
        RandomAccessFile randomAccessFile = AppContext.randomAccessFileMap.remove(param.getId());
        if (randomAccessFile != null) {
            randomAccessFile.close();
        }
        System.out.println("发送方资源关闭");
    }

    @Override
    public String getCode() {
        return ServiceSendCode.CLOSE_RESOURCES;
    }

}
